package com.jianz.campus_markets.controller;


import com.jianz.campus_markets.domain.ResponseResult;
import com.jianz.campus_markets.domain.dto.ProductDto;
import com.jianz.campus_markets.domain.entity.Product;
import com.jianz.campus_markets.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jianz
 * @since 2023-11-22
 */
@RestController
@RequestMapping("/product")
@Api(value = "商品模块")
public class ProductController {

    @Autowired
    private ProductService productService;

    /**
     *
     *  用户个人商品Api
     */

    @PostMapping("/add")
    @ApiOperation(value = "用户添加商品(未审核)")
    public ResponseResult addProduct(@RequestBody ProductDto product) {

        return productService.addProduct(product);
    }

    @GetMapping("/getUnauditedProduct")
    @ApiOperation(value = "用户获取审核中商品")
    public ResponseResult getUnauditedProduct(){
        return productService.getUnauditedProduct();
    }

    @GetMapping("/getFailedProduct")
    @ApiOperation(value = "用户获取审核失败商品")
    public ResponseResult getFailedProduct(){
        return productService.getFailedProduct();
    }

    @GetMapping("/getPassProduct")
    @ApiOperation(value = "用户获取审核成功商品")
    public ResponseResult getPassProduct(){
        return productService.getPassProduct();
    }

    @GetMapping("/getPassProductById")
    @ApiOperation(value = "获取用户审核成功商品")
    public ResponseResult getPassProductById(int id){
        return productService.getPassProductById(id);
    }

    @DeleteMapping("/deleteProduct")
    @ApiOperation(value = "用户删除自己发布的商品")
    public ResponseResult deleteProduct(int productId){
        return productService.deleteProduct(productId);
    }

    @PutMapping("/update")
    @ApiOperation(value = "用户根据商品id更新已发布商品信息，更新后进入未审核状态")
    public ResponseResult updateProduct(@RequestBody Product product){
        return productService.updateProduct(product);
    }

    /**
     *  购物Api
     *
     */

    @GetMapping("/getAllProduct")
    @ApiOperation(value = "浏览全部审核已通过的商品")
    public ResponseResult getAllProduct(){
        return productService.getAllProduct();
    }

    @GetMapping("/getProductInfo")
    public ResponseResult getProductInfo(int productId){
        return productService.getProductInfo(productId);
    }
}

